package extend.org.compiere.hrm;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.LinkedHashMap;
import java.util.logging.Level;

import org.compiere.model.X_hrm_set_tax;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;

public class TaxVariable {
	
	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (TaxVariable.class);
	
	private double IPN;
	private double OPV;
	private double CNALOG;
	private double COTCH;
	private double MZP;
	private double MRP;
	private double MAXPENSION;
	private double MINPENSION;
	private double PENSIONBASE;
	private double SUM;
	private double TOTAL;	
	
	/** */
	private Timestamp dateFrom;
	/** */
	private LinkedHashMap<String, Double> map = new LinkedHashMap<String, Double>();
	
	public TaxVariable(){
		//
	}
	
	public TaxVariable(Timestamp dt){
		this.dateFrom = dt;
		setValue();
	}
	
	public double getIPN() {
		return IPN;
	}
	public void setIPN(double iPN) {
		IPN = iPN;
	}
	public double getOPV() {
		return OPV;
	}
	public void setOPV(double oPV) {
		OPV = oPV;
	}
	public double getCNALOG() {
		return CNALOG;
	}
	public void setCNALOG(double cNALOG) {
		CNALOG = cNALOG;
	}
	public double getCOTCH() {
		return COTCH;
	}
	public void setCOTCH(double cOTCH) {
		COTCH = cOTCH;
	}
	public double getMZP() {
		return MZP;
	}
	public void setMZP(double mZP) {
		MZP = mZP;
	}
	public double getMRP() {
		return MRP;
	}
	public void setMRP(double mRP) {
		MRP = mRP;
	}
	public double getMAXPENSION() {
		return MAXPENSION;
	}
	public void setMAXPENSION(double mAXPENSION) {
		MAXPENSION = mAXPENSION;
	}
	public double getMINPENSION() {
		return MINPENSION;
	}
	public void setMINPENSION(double mINPENSION) {
		MINPENSION = mINPENSION;
	}
	public double getPENSIONBASE() {
		return PENSIONBASE;
	}
	public void setPENSIONBASE(double pENSIONBASE) {
		PENSIONBASE = pENSIONBASE;
	}
	public double getSUM() {
		return SUM;
	}
	public void setSUM(double sUM) {
		SUM = sUM;
	}
	public double getTOTAL() {
		return TOTAL;
	}
	public void setTOTAL(double tOTAL) {
		TOTAL = tOTAL;
	}

	private void setValue(){
		
	    PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		String sql = "SELECT hrm_taxtype, rate FROM HRM_SET_TAX \n" +
					  "WHERE "+DB.TO_DATE(dateFrom, true) + " BETWEEN STARTDATE AND ENDDATE";			
		try
		{
			pstmt = DB.prepareStatement(sql,null);				
			rs = pstmt.executeQuery();	
			while(rs.next())
				// key-TYPE, value-Rate
				map.put(rs.getString(1), rs.getDouble(2));
		}
		catch (SQLException e)
		{
			s_log.log(Level.SEVERE, "product", e);
		}
		finally
		{
			DB.close(rs, pstmt);
			rs = null; pstmt = null;
		}	
		
		for(String type :map.keySet()){
			
			if(type.equals(X_hrm_set_tax.HRM_TAXTYPE_MZP))
				setMZP(map.get(type));
			else if(type.equals(X_hrm_set_tax.HRM_TAXTYPE_OPV))
				setOPV(map.get(type));
			else if(type.equals(X_hrm_set_tax.HRM_TAXTYPE_MRP))
				setMRP(map.get(type));
			else if(type.equals(X_hrm_set_tax.HRM_TAXTYPE_IPN))
				setIPN(map.get(type));
			else if(type.equals(X_hrm_set_tax.HRM_TAXTYPE_CNALOG))
				setCNALOG(map.get(type));
			else if(type.equals(X_hrm_set_tax.HRM_TAXTYPE_COTCH))
				setCOTCH(map.get(type));
			else if(type.equals(X_hrm_set_tax.HRM_TAXTYPE_MAXPENSION))
				setMAXPENSION(map.get(type));
			else if(type.equals(X_hrm_set_tax.HRM_TAXTYPE_MINPENSION))
				setMINPENSION(map.get(type));
			else if(type.equals(X_hrm_set_tax.HRM_TAXTYPE_PENSIONBASE))
				setPENSIONBASE(map.get(type));
		}
		
	}
	
}	
